package com.hitechbangla.fctu.base.aircraft;

import java.io.ObjectOutputStream;
import com.hitechbangla.fctu.utility.GeneralUtil;
import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import com.hitechbangla.fctu.utility.enumall.AircraftTypeSaveFlag;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author deb kanti
 */
public class AircraftType implements Serializable
{    
    private String typename;  // this is the id, e.g. F7, Mig29..
    private float cruisingSpeed;    
    private float missileRange;
    private float fuelCapacity;
    private AircraftTurnDegree aircraftTurnDegree;    
    private float climbRate;
    
    private static final long serialVersionUID = 1L;
    
    /**
     *
     */
    public AircraftType(String typename,float cruisingSpeed,float missileRange, float fuelCapacity, AircraftTurnDegree aircraftTurnDegree, float climbRate)
    {
        this.typename = typename;
        this.cruisingSpeed = cruisingSpeed;        
        this.missileRange = missileRange;
        this.fuelCapacity = fuelCapacity;
        this.aircraftTurnDegree = aircraftTurnDegree;
        this.climbRate = climbRate;
    }   

    /**
     * @return the cruisingSpeed
     */
    public float getCruisingSpeed() {
        return cruisingSpeed;
    }

    /**
     * @param cruisingSpeed the cruisingSpeed to set
     */
    public void setCruisingSpeed(float cruisingSpeed) {
        this.cruisingSpeed = cruisingSpeed;
    }

    /**
     * @return the callSign
     */
    
    /**
     * @return the missileRange
     */
    public float getMissileRange() {
        return missileRange;
    }

    /**
     * @param missileRange the missileRange to set
     */
    public void setMissileRange(float missileRange) {
        this.missileRange = missileRange;
    }

    /**
     * @return the fuelCapacity
     */
    public float getFuelCapacity() {
        return fuelCapacity;
    }

    /**
     * @param fuelCapacity the fuelCapacity to set
     */
    public void setFuelCapacity(float fuelCapacity) {
        this.fuelCapacity = fuelCapacity;
    }
    
    

    /**
     * @return the aircraftTurnDegree
     */
    public AircraftTurnDegree getAircraftTurnDegree() 
    {
        return aircraftTurnDegree;
    }

    /**
     * @param aircraftTurnDegree the aircraftTurnDegree to set
     */
    public void setAircraftTurnDegree(AircraftTurnDegree aircraftTurnDegree) 
    {
        this.aircraftTurnDegree = aircraftTurnDegree;
    }
    
    public String getTypename() 
    {
        return typename;
    }
    
    public static List<AircraftType> getAllAircraftType()
    {
        try
        {
            FileInputStream fileInputStream = new FileInputStream("src/resources/aircraftType.object");
            ObjectInputStream  objectInputStream = new ObjectInputStream(fileInputStream);

            List<AircraftType> listAircraftType = (List<AircraftType>) objectInputStream.readObject();            
            objectInputStream.close();
            return listAircraftType;            
        }
        catch(Exception ex)
        {
            return null;
        }
    }
    
    public static void updateAircraft(List<AircraftType> listAircraftType)
    {
	try
	{
	    FileOutputStream fileOutputStream = new FileOutputStream("src/resources/aircraftType.object");
	    ObjectOutputStream  objectOutputStream = new ObjectOutputStream(fileOutputStream);

	    objectOutputStream.writeObject(listAircraftType);
	    objectOutputStream.close();
	}
	catch(Exception ex)
	{
	    
	}
    }
    
    
    public static AircraftType  getAircraftTypeByTypename(String typename)
    {      
        AircraftType tempAircraftType  = null;
        try
        {
            FileInputStream fileInputStream = new FileInputStream("src/resources/aircraftType.object");
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            List<AircraftType> listAircraftType = (ArrayList<AircraftType>)objectInputStream.readObject();         
            
            for(AircraftType aircraftType: listAircraftType)    
            {
                if(aircraftType.getTypename().equals(typename))
                {
                    return aircraftType;
                }
            }
        }       
        catch(Exception ex)
        {
            //System.out.println(ex.toString());
        }
         
        
        return null;
    }
    
    public static void main(String a[])
    {
        AircraftType aircraftType = getAircraftTypeByTypename("Mig29");
        //System.out.println(aircraftType.getFuelCapacity());
    }

    /**
     * @return the climbRate
     */
    public float getClimbRate() {
        return climbRate;
    }

    /**
     * @param climbRate the climbRate to set
     */
    public void setClimbRate(float climbRate) {
        this.climbRate = climbRate;
    }
    
    
    
}
